package dormouse.vfs.ui;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import org.apache.commons.vfs2.FileObject;

/**
 * This class is used to render the first column of a table of FileObjects.
 * This renderer places an icon at the left side of the renderer to indicate
 * the type of file or directory being viewed.
 * 
 * @author mfortner
 * 
 */
public class FileTableCellRenderer extends DefaultTableCellRenderer {

	/**
	 * {@inheritDoc}
	 */
	public Component getTableCellRendererComponent(JTable table,
			Object fileObj, boolean isSelected, boolean hasFocus, int row,
			int column) {

		FileObject file = null;
		FileListTableModel model = (FileListTableModel) table.getModel();
		file = model.getFileAt(row);
		this.setIcon(IconFactory.getInstance(file, IconFactory.SIZE_16));
		String filename = file.getName().getBaseName();
		this.setText(filename);
		
		this.setVerticalTextPosition(JLabel.CENTER);
		this.setHorizontalTextPosition(JLabel.RIGHT);
		this.setIconTextGap(3);


		setToolTipText(filename); // Discussed in the
														// following section
		return this;
	}
}
